##################################
#-*- coding:utf8 -*-             #
from urllib  import FancyURLopener
from util import path
from conf import dir
import os
'''
Created on 2009-11-11

@author: Jialai_Zhu
'''
class PyFF(FancyURLopener,object):
    version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'

class browser(object):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
        self.output_template_index=0
        
    def new_output(self):
        prefix=dir.download+r'\result'
        self.output_template_index=self.output_template_index+1
        output=prefix+'%d'%(self.output_template_index)+".html"
        return output        
    def run(self,search_criteria,output_file=''):   
        ff=PyFF()
        ffp=ff.open(search_criteria)
        pwd=os.getcwd()
        if output_file=='':
            html_file=self.new_output()
        else:
            html_file=output_file    
        print html_file
        ff.retrieve(search_criteria,html_file)
        ff.close()
        return html_file      

#="d:\\threat solution\\eclipse\\workspace\\ciss\\src\\result.html"     